home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows2 / hp22d3.zip / REFGUIDE / CONTANRS.TXT < prev    next >
Text File  |  1991-05-16  |  9KB  |  262 lines

  1.  
  2.  
  3.  
  4.  
  5.     ________________________________________________________________________
  6.                                               Chapter 4: Containers   41
  7.     ________________________________________________________________________
  8.  
  9.  
  10.     CHAPTER FOUR:  CONTAINERS
  11.  
  12.     HyperPAD offers four storage facilities, called containers, in which you
  13.     can store data. These four containers are fields, variables, the message
  14.     box, and the selectedText. Each of these containers can hold up to 32000
  15.     characters (depending on available memory).
  16.  
  17.     The commands get and put allow you to manipulate the contents of
  18.     containers (Use set with the selectedText). For example:
  19.  
  20.     put "hello there" into page field 1;
  21.  
  22.     put 18.2 * 56.78 into subTotal;
  23.  
  24.     put "Please Wait..." into the message box;
  25.  
  26.     set the selectedText to "hello there";
  27.  
  28.  
  29.     FIELDS
  30.  
  31.     Fields are display and retrieval areas for text within your pads. Fields
  32.     do not have a fixed length, as they do in some database programs. They
  33.     can hold any length of text up to 32000 characters, making them
  34.     efficient storage devices. The following examples show how to manipulate
  35.     a field's contents using the PADtalk commands put and get.
  36.  
  37.     put "This is a test" into field "Status";
  38.  
  39.     put field 2 before word 2 of field "Status";
  40.  
  41.     get page field id 6;     -- into "it"
  42.  
  43.  
  44.  
  45.     ________________________________________________________________________
  46.                                               Chapter 4: Containers   42
  47.     ________________________________________________________________________
  48.  
  49.  
  50.     VARIABLES
  51.  
  52.     A variable is a named container that you can use to store data within
  53.     your script. Like fields, variables can hold up to 32000 characters. The
  54.     name of a variable can be up to 255 characters long, but it is usually
  55.     beneficial to keep the name a readable length. Variable names must start
  56.     with a letter, underscore (_) or $ and contain no spaces. The following
  57.     are examples of variable names:
  58.  
  59.     TaxResult
  60.     R6
  61.     i
  62.     $fixedAmount
  63.     CalculatedTotal
  64.     _total_with_adjustments
  65.  
  66.     You do not need to declare variables before using them in HyperPAD (as
  67.     you do in other languages). You just put something into them.
  68.  
  69.     Variables in HyperPAD have no type, as they do in other languages.
  70.     HyperPAD makes no distinction between text and numbers. Thus, the
  71.     following operations are legal:
  72.  
  73.     10 + i
  74.     "10" + i
  75.     (word 2 of "hello 5 there") + 67.89 - i
  76.     56 & i & "hello"
  77.  
  78.     If you attempt to apply a mathematical operator to text, however, you
  79.     will receive an error message. For example:
  80.  
  81.     5 + "hello"
  82.  
  83.     Because variables in HyperPAD can be either textual or numeric, the
  84.     number 0 and the text quantity empty ("") have special meaning. In fact,
  85.     they are equivalent. When a variable is first introduced, its value is
  86.     initially empty (""). If the variable is then used in a comparison with
  87.     another text quantity, the value will be empty (no length). If it is in
  88.     a comparison with a number, its value will be 0.
  89.  
  90.     The equivalence of 0 and empty is important when performing comparisons.
  91.     Consider the following comparison in PADtalk:
  92.  
  93.     if i is empty then......
  94.  
  95.     When HyperPAD compares the two quantities (i and empty), it will attempt
  96.     to convert both to numbers (HyperPAD first tries to compare numbers,
  97.     then text). If i is initially empty, then the conversion will change the
  98.  
  99.  
  100.  
  101.     ________________________________________________________________________
  102.                                               Chapter 4: Containers   43
  103.     ________________________________________________________________________
  104.  
  105.  
  106.     value of i to 0. When this occurs, you can rewrite the comparison as
  107.     follows:
  108.  
  109.     if i & "x" is "x" then......
  110.  
  111.     This forces HyperPAD to compare two quantities as text and avoid its
  112.     internal conversion to numbers.
  113.  
  114.     Internally, HyperPAD keeps track of whether a variable is textual or
  115.     numeric. HyperPAD will not perform any internal conversions if the
  116.     variable is being used in accordance with its current type. This greatly
  117.     speeds up script execution by reducing internal conversions.
  118.  
  119.  
  120.     LOCAL VARIABLES
  121.  
  122.     A local variable is a temporary storage container used during the
  123.     execution of a handler. When the handler has completed execution, the
  124.     local variables are relinquished. The following is a handler that uses a
  125.     local variable called temp:
  126.  
  127.     handler select;
  128.     begin
  129.       put 10 * 5 into temp;
  130.       put temp into page field 1;
  131.     end;
  132.  
  133.     Access to local variables is faster than access to any other type of
  134.     container. Thus, to speed up a script you may want to copy global
  135.     variables or field contents into a local variable, like in the following
  136.     example:
  137.  
  138.     put page field 1 into temp; -- make a copy
  139.     for i = 1 to 10 do
  140.       if line i of temp is "lawyer" then beep;
  141.  
  142.     This example stores the data from a field in the local variable temp to
  143.     speed up the loop that follows.
  144.  
  145.     Every handler reserves a special local variable called it. This is used
  146.     to hold temporary results and is even used by some commands to return
  147.     values. For example:
  148.  
  149.     get page field 1;   -- puts the data into "it"
  150.     put it into the message box;
  151.  
  152.     ask "What is your name?";     -- puts response into "it"
  153.     if it is "joe" then beep;
  154.  
  155.     Using the variable it enhances the readability of your PADtalk scripts.
  156.  
  157.  
  158.  
  159.     ________________________________________________________________________
  160.                                               Chapter 4: Containers   44
  161.     ________________________________________________________________________
  162.  
  163.  
  164.     GLOBAL VARIABLES
  165.  
  166.     Global variables are accessible from all handlers and functions. Global
  167.     variables stay around until you exit HyperPAD or run another program.
  168.     You can tell your handler that a variable is global using the  global
  169.     statement. The following statement declares two global variables
  170.     lineCount and totalPrice:
  171.  
  172.     global lineCount,totalPrice;
  173.  
  174.     When you are done using global variables, you may want to delete their
  175.     values to save memory. You can do this using the delete or put command:
  176.  
  177.     put empty into lineCount;
  178.  
  179.     delete totalPrice;
  180.  
  181.     The following handler uses a global variable called previousText to
  182.     store the user's last response to the ask statement:
  183.  
  184.     handler select;
  185.     begin
  186.       global previousText;
  187.       ask "Where do you live" with previousText;
  188.       put it into previousText;
  189.     end;
  190.  
  191.  
  192.     PARAMETER VARIABLES
  193.  
  194.     Parameter variables are place holders that attach names to values which
  195.     are passed to handlers and functions. Parameter variables are similar to
  196.     local variables in that they can only be used within the handler in
  197.     which they are declared. The following example shows a handler that
  198.     declares some parameter variables and how to call it:
  199.  
  200.     handler CalculateResult(interest,periods);
  201.     begin
  202.       put interest * periods / 365 into page field 1;
  203.     end;
  204.  
  205.     handler select;
  206.     begin
  207.       CalculateResult 12 / 100,36;
  208.     end;
  209.  
  210.  
  211.  
  212.     ________________________________________________________________________
  213.                                               Chapter 4: Containers   45
  214.     ________________________________________________________________________
  215.  
  216.  
  217.     THE MESSAGE BOX
  218.  
  219.     The message box is a container that has two uses:
  220.  
  221.     1.  You can display messages for the pad user.
  222.  
  223.     2.  You can type in commands and execute them immediately.
  224.  
  225.     The following example uses the message box to tell the user to wait:
  226.  
  227.     show the message box;
  228.     put "Please Wait..." into the message box;
  229.  
  230.     The message box is the default destination of the put command. For
  231.     example, the following statements do the same thing:
  232.  
  233.     put "Please Wait...";
  234.  
  235.     put "Please Wait..." into the message box;
  236.  
  237.     The message box can be referred to by:
  238.  
  239.     the message box
  240.     message
  241.     msg
  242.     msg box
  243.  
  244.  
  245.     THE SELECTEDTEXT
  246.  
  247.     The selectedText is another storage facility into which you can put
  248.     information. Also, text is automatically stored here when the user
  249.     highlights text in a field (using the SHIFT+ARROW keys or dragging the
  250.     mouse). You can use put and get to retrieve its contents:
  251.  
  252.     put the selectedText into page field 1;
  253.  
  254.     get the selectedText;    -- put it into "it"
  255.  
  256.     However, unlike other containers, you can only set its value using the
  257.     set command:
  258.  
  259.     set the selectedText to "hello there";
  260.     set the selectedText to empty;
  261.  
  262.     Changing the value of the selectedText has no effect on the display.